{extend name="layout/iframe" /}

{block name="pagecss"}
<link href="__STATIC__/plugins/layui-formSelects/formSelects-v4.css" rel="stylesheet" type="text/css" />
{/block}

{block name="content"}
<div class="layui-card-body layui-layout-admin" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>是否启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" {if condition="($info.status == 1)"}checked=""{/if} lay-skin="switch" lay-text="启用|禁用"><div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>启用</em><i></i></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>选择商品</label>
            <div class="layui-input-block">
                <input type="hidden" class="layui-input product_id" name="product_id" value="{$info.product_id}" data-value="{$info.product_id}" lay-verify="product_id">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid select-products" style="float: right;">{$info.product.name}</button>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>活动类型</label>
            <div class="layui-input-block promotion_type" data-value="{$info.promotion_type}">
                <input type="radio" name="promotion_type" value="1" title="特价" lay-filter="promotion_type" {if condition="($info.promotion_type == 1)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>特价</div></div>
                <input type="radio" name="promotion_type" value="2" title="折扣" lay-filter="promotion_type" {if condition="($info.promotion_type == 2)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>折扣</div></div>
                <input type="radio" name="promotion_type" value="3" title="立减" lay-filter="promotion_type" {if condition="($info.promotion_type == 3)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>立减</div></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">原价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input product_price" name="ori_price" value="{$info.ori_price / 100}" placeholder="" autocomplete="off" readonly>
                </div>
            </div>
            <div class="layui-inline price-div">
                <label class="layui-form-label"><span class="required">*</span>特价</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="price" {if condition="($info.promotion_type == 1)"}value="{$info.promotion_discount / 100}"{/if} maxlength="10" lay-verify="price" placeholder="" autocomplete="off">
                </div>
            </div>
            <!--<div class="layui-inline discount-div layui-hide">-->
            <div class="layui-inline discount-div" style="display: none;">
                <label class="layui-form-label"><span class="required">*</span>折扣</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="discount" {if condition="($info.promotion_type == 2)"}value="{$info.promotion_discount / 100}"{/if} maxlength="5" lay-verify="discount" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline reduce_price-div" style="display: none;">
                <label class="layui-form-label"><span class="required">*</span>立减</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="reduce_price" {if condition="($info.promotion_type == 3)"}value="{$info.promotion_discount / 100}"{/if} maxlength="10" lay-verify="reduce_price" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>每单限购</label>
            <div class="layui-input-block buy_limit_type" data-value="{$info.buy_limit_type}">
                <input type="radio" name="buy_limit_type" value="1" title="1份" lay-filter="buy_limit_type" {if condition="($info.buy_limit_type == 1)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>1份</div></div>
                <input type="radio" name="buy_limit_type" value="2" title="不限" lay-filter="buy_limit_type" {if condition="($info.buy_limit_type == 2)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>不限</div></div>
                <input type="radio" name="buy_limit_type" value="3" title="自定义" lay-filter="buy_limit_type" {if condition="($info.buy_limit_type == 3)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>自定义</div></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text buy_limit_num-div" style="display: none;">
            <label class="layui-form-label"><span class="required">*</span>自定义数量</label>
            <div class="layui-input-block">
                <input type="number" class="layui-input" name="buy_limit_num" value="{$info.buy_limit_num}" maxlength="10" lay-verify="buy_limit_num" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>开始日期</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input start_date" name="start_time" value="{$info.start_time}" lay-verify="required" placeholder="" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="required">*</span>结束日期</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input end_date" name="end_time" value="{$info.end_time}" lay-verify="required" placeholder="" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>生效日期</label>
            <div class="layui-input-block">
                <input type="hidden" class="layui-input effective_date" name="effective_date" value='{$info.effective_date}' lay-verify="effective_date">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid set-effective_date" style="float: right;">生效日期</button>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>面向用户</label>
            <div class="layui-input-block to_user_type" data-value="{$info.to_user_type}">
                <input type="radio" name="to_user_type" value="1" title="全部用户" lay-filter="to_user_type" {if condition="($info.to_user_type == 1)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>全部用户</div></div>
                <input type="radio" name="to_user_type" value="2" title="新用户" lay-filter="to_user_type" {if condition="($info.to_user_type == 2)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>新用户</div></div>
                <input type="radio" name="to_user_type" value="3" title="会员" lay-filter="to_user_type" {if condition="($info.to_user_type == 3)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>会员</div></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text user_ids-div" style="display: none;">
            <label class="layui-form-label"><span class="required">*</span>选择会员</label>
            <div class="layui-input-block">
                <select name="to_users" id="memberlevelIds" xm-select="memberlevelIds" lay-verify="to_users">
                    {foreach name="memberlevelList" item="memberlevel" key="memberlevelKey"}
                        <option value="{$memberlevel.id}" {if condition="(in_array($memberlevel.id, $info.to_users))"}selected=""{/if}>{$memberlevel.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>适用范围</label>
            <div class="layui-input-block range" data-value="{$info.range}">
                <input type="radio" name="range" value="1" title="全部门店" lay-filter="range" {if condition="($info.range == 1)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>全部门店</div></div>
                <input type="radio" name="range" value="2" title="线上商城" lay-filter="range" {if condition="($info.range == 2)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>线上商城</div></div>
                <input type="radio" name="range" value="3" title="线下门店" lay-filter="range" {if condition="($info.range == 3)"}checked=""{/if}>
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>线下门店</div></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text store_ids-div" style="display: none;">
            <label class="layui-form-label"><span class="required">*</span>选择门店</label>
            <div class="layui-input-block">
                <select name="store_ids" id="storeIds" xm-select="storeIds" lay-verify="store_ids">
                    {foreach name="storeList" item="store" key="storeKey"}
                        <option value="{$store.id}" {if condition="(in_array($store.id, $info.store_ids))"}selected=""{/if}>{$store.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <input type="hidden" name="id" value="{$info.id}">

        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <div class="layui-footer">
                    <button type="button" class="layui-btn layui-btn-primary close-btn">取消</button>
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="laySave">保存 <i class="layui-icon">&#xe609;</i></button>
                </div>
            </div>
        </div>
    </form>
</div>

<input type="hidden" class="save_url" value="{:url('admin/'.strtolower($model).'/savepost')}">
<input type="hidden" class="check_product_url" value="{:url('admin/'.strtolower($model).'/checkProduct')}">

<input type="hidden" class="select_products_url" value="{:url('admin/flashsale/selectproducts')}">
<input type="hidden" class="set_effective_date_url" value="{:url('admin/flashsale/seteffectivedate')}">
{/block}

{block name="pagescript"}
<script src="__STATIC__/admin/pages/js/flashsale.js" type="text/javascript"></script>
<script>
    layui.use(['layer', 'laydate'], function(){
        var $ = layui.jquery,
            laydate = layui.laydate;
        // 执行一个laydate实例
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var minDate = year + seperator1 + month + seperator1 + strDate;
        //console.log(minDate);
        var startDate = laydate.render({
            elem: '.start_date', //指定元素
            type: 'date',
            format: 'yyyy-MM-dd',
            min: minDate, //设定最小日期为当前日期
            trigger: 'click',
            done: function(value, date){
                //endDate.config.min.year = date.year;
                //endDate.config.min.date = date.date;

                endDate.config.min.year = date.year;
                endDate.config.min.month = date.month - 1;
                var day = date.date;
                if(date.hours == 23 && date.minutes == 59 && date.seconds == 59){
                    day = day + 1;
                }else{
                    endDate.config.min.hours = date.hours;
                    endDate.config.min.minutes = date.minutes;
                    endDate.config.min.seconds = date.seconds;
                }
                endDate.config.min.date = day;
            }
        });

        var endDate = laydate.render({
            elem: '.end_date',
            type: 'date',
            format: 'yyyy-MM-dd',
            min: minDate,
            trigger: 'click',
            done: function(value, date){
                //startDate.config.max.year = date.year;
                //startDate.config.max.date = date.date;

                startDate.config.max.year = date.year;
                startDate.config.max.month = date.month - 1;
                var day = date.date;
                if(date.hours == 0 && date.minutes == 0 && date.seconds == 0){
                    day = day - 1;
                }else{
                    startDate.config.max.hours = date.hours;
                    startDate.config.max.minutes = date.minutes;
                    startDate.config.max.seconds = date.seconds;
                }
                startDate.config.max.date = day;
            }
        });
    });
</script>
{/block}